<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>餐厅</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/layout.css" />
		<link rel="stylesheet" type="text/css" href="../../css/font-awesome-4.7.0/css/font-awesome.min.css" />
		<style>
			.jiesao {
				padding: 1rem 1rem 0.5rem 1rem;
				background-color: #FFFFFF;
			}
			
			.zhonglei {
				padding: 0.5rem;
				border-bottom: 1px solid #C0C0C0;
			}
			
			#jiesuan {
				background-color: rgb(209, 37, 34);
				color: #FFFFFF;
				padding-top: 1rem;
			}
			
			#logo img {
				width: 4rem;
			}
			
			#xiaofenlei {
				background-color: #FFFFFF;
			}
			
			#xiaofenlei div {
				padding: 0.9rem 0rem 0.3rem 0.3rem;
				border-bottom: 1px solid #C0C0C0;
				width: 5rem;
				height: 3rem;
				overflow: hidden;
				font-size: 0.8rem;
			}
			
			.nr {
				padding: 0rem 0.5rem 0.3rem 0.2rem;
				margin-left: 0.1rem;
				width: 77%;
				background-color: #FFFFFF;
				margin-bottom: 4rem;
			}
			
			.pt05 {
				padding-top: 0.5rem;
			}
			
			.pt05 div img {
				width: 4rem;
			}
			
			.wid {
				margin-left: 0.5rem;
				width: 70%;
			}
			
			.fc {
				font-size: 0.8rem;
				color: rgb(153, 153, 153);
			}
			
			.xname {
				height: 1.3rem;
				overflow: hidden;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="background-color: darkred;color: #FFFFFF;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #FFFFFF;"></a>
			<h1 class="mui-title" style="color: #FFFFFF;">餐厅</h1>
		</header>
		<div class="mui-content">
			<div class="jiesao">
				<div class="mui-pull-left" id="logo"></div>
				<div class="mui-pull-left" style="margin-left: 1rem;">
					<span id="dmingcheng" style="font-size: 1.2rem;"></span>
					<span id="Collection"></span><br/><span style="font-size: 0.8rem;color:rgb(153,153,153);">欢迎光临，用餐高峰请提前下单。</span></div>
				<div class="mui-clearfix"></div>
			</div>
			<!--jiesao-->
			<div style="height: 0.1rem;"></div>
			<div class="mui-pull-left" id="xiaofenlei"></div>
			<!--mui-pull-left-->
			<div class="mui-pull-left nr" id="xflneirong"></div>
			<nav class="mui-bar mui-bar-tab mui-text-center" id="jiesuan">
				<span style="font-size: 1.5rem;">结算</span></nav>
		</div>
		<!--mui-content-->
	</body>
	<script src="../../js/mui.min.js"></script>
	<!--script src="../js/domain.js" type="text/javascript" charset="utf-8"></script-->
	<script>
function genpost(p_strUrl,p_postJson)
{
	mui.post(p_strUrl,
	p_postJson.data,
	function(getdata)
	{
		p_postJson.success(getdata);
		
	},'json');
}

function checkCurrentUser(data)
{}

function checkLogin()
{
	return "651014";
}


		var baseUrl = "http://192.168.1.100:8080/";
		var workshopid = "";
		var rh = new Object();
			rh.ReqId = "123";
			rh.Salt = "xxx";
			rh.SesId = checkLogin();
		//mui.plusReady(function() {
			mui.ready(function(){
			
			//var self = plus.webview.currentWebview(); //获得当前页面的对象
			workshopid = 100;//self.workshopid;
			
			gouwuche();
			var rb = new Object();
			rb.workid = workshopid;
			rb.CatId = 1;

			var jn = new Object();
			jn.ReqHead = rh;
			jn.ReqBody = rb;

			var sendData = JSON.stringify(jn);

			genpost(baseUrl + "zdm/AppApi/Merchant/GetWorkshopInfo", {
				data: sendData,
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data) {
					checkCurrentUser(data);
					document.getElementById("dmingcheng").innerHTML = data.RespBody.workship_name;
					document.getElementById("logo").innerHTML = "<img src='" + data.RespBody.workship_name + "'/>";

				},
				error: function(xhr, type, errorThrown) {
					mui.toast("请重试");
				}

			}); //ajax
			


			xuanzhe('');
//			//获取分类
//			genpost(baseUrl + "zdm/AppApi/Search/CategoryList", {
//				data: sendData,
//				dataType: 'json', //服务器返回json格式数据
//				type: 'post', //HTTP请求类型
//				timeout: 10000, //超时时间设置为10秒；
//				headers: {
//					'Content-Type': 'application/json'
//				},
//				success: function(data) {
//					checkCurrentUser(data);
//
//					var res = data.RespBody;
//
//					var fl = "";
//					for(var i = 0; i < res.length; i++) {
//						fl += "<div onclick='xuanzhe(&quot;" + res[i].catid + "&quot;)'>" + res[i].catname + "</div>";
//					}
//					document.getElementById("xiaofenlei").innerHTML = fl;
//				},
//				error: function(xhr, type, errorThrown) {
//					mui.toast("请重试");
//				}
//			}); //ajax

			//判断店铺是否收藏
			var rb2 = new Object();
			rb2.WorkId = workshopid;

			var jn2 = new Object();
			jn2.ReqHead = rh;
			jn2.ReqBody = rb2;

			var sendData2 = JSON.stringify(jn2);

			genpost(baseUrl + "zdm/AppApi/Merchant/BeenCollected", {
				data: sendData2,
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data) {
					checkCurrentUser(data);
					if(data.RespBody.stat == 1) {
						document.getElementById("Collection").innerHTML = "<i class='fa fa-star' style='color:red;'></i>"
					} else if(data.RespBody.stat == 0) {
						document.getElementById("Collection").innerHTML = "<i class='fa fa-star-o' style='color:red;'></i>"
					}
				},
				error: function(xhr, type, errorThrown) {
					//异常处理；
					console.log(type);
				}
			}); //ajax

		}); //plusReady

		//获取购物车餐品列表
		function gouwuche() {

			var rb = new Object();
			rb.CatId = 1;

			var jn = new Object();

			jn.ReqHead = rh;

			jn.ReqBody = rb;

			var sendData = JSON.stringify(jn);
			genpost(baseUrl + "zdm/AppApi/ShopCart/GetMyGoodsInCart", {
				data: sendData,
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data) {
					checkCurrentUser(data);
					shops = data.RespBody;
					var objMap = new Array();
					for(var iTmp=0;iTmp<shops.length;iTmp++)
					{
						console.log(shops[iTmp].catid);
						var strKey = shops[iTmp].catid;
						if(objMap[strKey] == null)
						{
							objMap[strKey]=strKey;
						}
					}
					
					for(var key in objMap)
					{
						console.log("键:",key);
						//console.log("值:",objMap[key]);
					}
					
					//获取分类
					genpost(baseUrl + "zdm/AppApi/Search/CategoryList", {
						data: sendData,
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						headers: {
							'Content-Type': 'application/json'
						},
						success: function(data) {
							checkCurrentUser(data);
		
							var res = data.RespBody;
		
							var fl = "";
							for(var i = 0; i < res.length; i++) {
								var strCurCatId = res[i].catid;
								if(objMap[strCurCatId] != null)
									fl += "<div onclick='xuanzhe(&quot;" + strCurCatId + "&quot;)'>" + res[i].catname + "</div>";
							}
							document.getElementById("xiaofenlei").innerHTML = fl;
						},
						error: function(xhr, type, errorThrown) {
							mui.toast("请重试");
						}
					}); //ajax
					
				},
				error: function(xhr, type, errorThrown) {
					//异常处理；
					console.log(type);
				}
			}); //ajax
		} //gouwuche

		//点击左侧小分类
		function xuanzhe(catid) {
			var rb = new Object();
			rb.workid = workshopid;
			rb.CatId = catid;
			rb.curPage = 1;
			rb.pageSize = 500;
			rb.qryName = "";

			var jn = new Object();
			jn.ReqHead = rh;
			jn.ReqBody = rb;

			var sendData = JSON.stringify(jn);

			//获取分类下的餐品列表
			genpost(baseUrl + "zdm/AppApi/Search/GoodList", {
				data: sendData,
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data1) {

					genpost(baseUrl + "zdm/AppApi/ShopCart/GetMyGoodsInCart", {
						data: sendData,
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						headers: {
							'Content-Type': 'application/json'
						},
						success: function(data2) {
							var shops = data2.RespBody;
							var res = data1.RespBody.Recs;
							var flx = "";
							for(var i = 0; i < res.length; i++) {
								var number = 0;
								for(var j = 0; j < shops.length; j++) {
									if(res[i].goodid == shops[j].goods_id) {
										number = shops[j].buy_count;
									}
								}
								flx += "<div><div class='pt05'><div class='mui-pull-left'><img src='" + res[i].FilePath + "'/></div><div class='mui-pull-left wid'><div class='xname'>" + res[i].goodsname + "</div><div class='mui-pull-left'><span style='font-size: 0.8rem;color: rgb(209,37,34);'>￥<span id='price" + res[i].goodid + "'>" + res[i].price + "</span></span></div><div class='mui-pull-right'><span class='mui-icon mui-icon-minus' style='color: rgb(209,37,34);' onclick='jian(&quot;" + res[i].goodid + "_" + res[i].price + "_" + catid + "&quot;)' ></span><span style='font-size: 1rem;color: #000000;' id='" + res[i].goodid + "'>" + number + "</span><span class='mui-icon mui-icon-plus' style='color: rgb(209,37,34);'  onclick='jia(&quot;" + res[i].goodid + "_" + res[i].price + "_" + catid + "&quot;)'></span></div></div><div class='mui-clearfix'></div><div style='border-top:1px solid #cccccc;'></div></div></div>";
							}
							document.getElementById("xflneirong").innerHTML = flx;
						},
						error: function(xhr, type, errorThrown) {
							//异常处理；
							console.log(type);
						}
					}); //ajax
				},
				error: function(xhr, type, errorThrown) {
					mui.toast("请重试");
				}
			}); //ajax
		} //xuanzhe

		//减少数量
		function jian(idPrice) {
			var idp = idPrice.split("_");
			var id = idp[0];
			var price = idp[1];
			var catid = idp[2];

			if(document.getElementById(id).innerHTML.trim() > 0) {
				document.getElementById(id).innerHTML -= 1;
				if(document.getElementById(id).innerHTML > 0) {
					document.getElementById("price" + id).innerHTML = price * document.getElementById(id).innerHTML.trim();
				}

				rh.SesId = checkLogin();

				var rb = new Object();
				rb.goods_id = id;
				rb.buy_count = 1;

				var jn = new Object();
				jn.ReqHead = rh;
				jn.ReqBody = rb;
				var sendData = JSON.stringify(jn);
				genpost(baseUrl + "zdm/AppApi/ShopCart/deleteGoods2Cart", {
					data: sendData,
					dataType: 'json', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					headers: {
						'Content-Type': 'application/json'
					},
					success: function(data) {
						checkCurrentUser(data);
						if(data.RespBody.succ == 1) {
							//						alert("修改成功");
						} else {
							mui.toast("请重试！");
						}
					},
					error: function(xhr, type, errorThrown) {
						//异常处理；
						console.log(type);
					}

				}); //ajax
			}
		} //减少数量
		//增加数量
		function jia(idPrice) {

			var idp = idPrice.split("_");
			var id = idp[0]; //gooid
			var price = idp[1];
			var catid = idp[2];

			document.getElementById(id).innerHTML = parseInt(document.getElementById(id).innerHTML) + 1;
			document.getElementById("price" + id).innerHTML = price * document.getElementById(id).innerHTML.trim();

			rh.SesId = checkLogin();

			var rb = new Object();
			rb.goods_id = id;
			rb.buy_count = 1;

			var jn = new Object();
			jn.ReqHead = rh;
			jn.ReqBody = rb;
			var sendData = JSON.stringify(jn);
			genpost(baseUrl + "zdm/AppApi/ShopCart/SaveGoods2Cart", {
				data: sendData,
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data) {
					checkCurrentUser(data);
					if(data.RespBody.succ == 1) {
						//						alert("添加成功");
					} else {
						mui.toast("请重试！");
					}
				},
				error: function(xhr, type, errorThrown) {
					//异常处理；
					console.log(type);
				}

			}); //ajax

		} //增加数量

		document.getElementById("jiesuan").onclick = function() {
			//打开新窗口
			mui.openWindow({
				url: 'querendingdan.html', //需要打开页面的url地址 
				id: 'querendingdan', //需要打开页面的url页面id
				styles: {
					top: '0px', //新页面顶部位置 
					bottom: '0px', //新页面底部位置 
				},
				extras: {
					workid: workshopid
				},
				show: { //控制打开页面的类型
					autoShow: true,
					aniShow: 'zoom-fade-out', //页面显示动画，默认为”slide-in-right“；  页面出现的方式 左右上下
					duration: '300' //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒； 
				},
				waiting: { // 控制 弹出转圈框的信息
					autoShow: true, //自动显示等待框，默认为true 
					title: '正在加载...', //等待对话框上显示的提示内容 
					options: {
						width: '300px', //等待框背景区域宽度，默认根据内容自动计算合适宽度 
						height: '300px', //等待框背景区域高度，默认根据内容自动计算合适高度 ...... 
					}
				}
			}); //openWindow

		} //jiesuan

		//收藏
		document.getElementById("Collection").onclick = function() {

			rh.SesId = checkLogin();
			var rb = new Object();
			rb.WorkId = workshopid;

			var jn = new Object();
			jn.ReqHead = rh;
			jn.ReqBody = rb;

			var sendData = JSON.stringify(jn);

			genpost(baseUrl + "zdm/AppApi/Merchant/CollectMerchant", {
				data: sendData,
				dataType: 'json', //服务器返回json格式数据
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				headers: {
					'Content-Type': 'application/json'
				},
				success: function(data) {
					checkCurrentUser(data);
					if(data.RespBody.succ == 1) {
						document.getElementById("Collection").innerHTML = "<i class='fa fa-star' style='color:red;'></i>"
					} else if(data.RespBody.succ == 0) {
						document.getElementById("Collection").innerHTML = "<i class='fa fa-star-o' style='color:red;'></i>"
					}
				},
				error: function(xhr, type, errorThrown) {
					//异常处理；
					console.log(type);
				}
			}); //ajax
		} //Collection
	</script>
	</body>

</html>